<?php
/**
 * country.php
 *
 * Created on 2014-12-5
 * Create by LDD
 */
namespace haibao\cms\data;

use \haibao\cms\model\filter\City as CityFilter;

class City extends \haibao\cms\data\BaseMysql{
	
	private static $xcacheCountryPrefix = 'Country';
	private static $xcacheCityPrefix = 'City';
	
	public function __construct(){
		parent::__construct('\haibao\cms\model\data\City');
	}

	public function getCitysByCountryValue($countryValue){
		$city = json_decode($this->getCache(self::$xcacheCountryPrefix.$countryValue), true);
		if(!$city){
			$cityFilter = new CityFilter();
			$cityFilter->where(CityFilter::CONDITION_FIELD_NAME_COUNTRY_VALUE,\haibao\frame\data\query\Condition::CONDITION_EQUAL, $countryValue);
			$city =	parent::getAll($cityFilter);
			$this->setCache(self::$xcacheCountryPrefix.$countryValue, json_encode($city));
		}
		return $city;
	}
	
	public function getCityByCityValue($cityValue){
		$city = json_decode($this->getCache(self::$xcacheCityPrefix.$cityValue));
		if(!$city){
			$cityFilter = new CityFilter();
			$cityFilter->where(CityFilter::CONDITION_FIELD_NAME_DATA_VALUE,\haibao\frame\data\query\Condition::CONDITION_EQUAL, $cityValue);
			$city = parent::getOne($cityFilter);
			$this->setCache(self::$xcacheCityPrefix.$cityValue, json_encode($city));
		}
		return $city;
	}
}